//
//  HomeViewController.m
//  JackToolsBox
//
//  Created by Jack Xue on 2019/12/12.
//  Copyright © 2019 Jack Xue. All rights reserved.
//

#import "HomeViewController.h"
#import "ImageDemoViewController.h" //下载图片Demo
#import "TagViewDemoController.h"   //tagview二合一Demo
#import "HorizonViewDemoController.h"   //模拟collectionView
#import "JKPurchaseVC.h"
#import "PurchaseManagerViewController.h"



@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *_tableView;
    NSArray *_dataArray;
}
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, JK_Nav_Height, JK_Main_Width, JK_Main_Height - (JK_Nav_Height)) style:(UITableViewStyleGrouped)];
    _tableView.rowHeight = 44;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    _dataArray = @[@"图片下载Demo",@"TagView-drawRect",@"TagView-subView",@"JkHorizonDemo",@"purchase",@"receipt manager"];
}

#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    /*
     使用代码重用tableViewCell
     为什么用static - https://www.cnblogs.com/stevenwuzheng/p/5377919.html
     */
    static NSString *cellId = @"functionListCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = _dataArray[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        //下载图片Demo
        ImageDemoViewController *new = [ImageDemoViewController new];
        [self.navigationController pushViewController:new animated:YES];
    }else if (indexPath.row == 1){
        //使用drawRect实现的tagView
        TagViewDemoController *new = [TagViewDemoController new];
        new.isDrawRect = YES;
        [self.navigationController pushViewController:new animated:YES];
    }else if (indexPath.row == 2){
        //使用layoutSubview实现的tagView
        TagViewDemoController *new = [TagViewDemoController new];
        [self.navigationController pushViewController:new animated:YES];
    }else if (indexPath.row == 3){
        HorizonViewDemoController *new = [HorizonViewDemoController new];
        [self.navigationController pushViewController:new animated:YES];
    }else if (indexPath.row == 4){
        JKPurchaseVC *vc = [[JKPurchaseVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        vc = nil;
    }else if (indexPath.row == 5){
        PurchaseManagerViewController *vc = [[PurchaseManagerViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
